import inputCommon from '../../../../mixin/inputCommon'
import JsBarcode from 'jsbarcode'

export default {
  name: 'render',
  props: ['config', 'readonlyMain', 'isMobile', 'editor'],
  inject: ['rootForm'],
  mixins: [inputCommon],
  data() {
    return {
      valEmpty: true
    }
  },
  mounted() {
    this.$watch(this.getParsedEx('contentExpression'), (v) => {
      let options = {
        lineColor: this.config.lineColor,
        width: this.config.width,
        height: this.config.height,
        displayValue: this.config.displayValue
      }
      if (v) {
        this.valEmpty = true
        this.$nextTick(() => {
          this.$el.classList && this.$el.classList.add(this.pluginUniqueId)
          JsBarcode(`.${this.pluginUniqueId} .canvas`, v, options)
        })
      } else {
        this.valEmpty = false
      }
    }, { immediate: true })
  }
}
